import { store, storeCommitPath } from "..";

export const AuthenticationStore = {
  namespaced: true,
  state: {
    isLoggedIn: false,
    userName: "",
    userID: "",
    EntNum: "",
    accessToken: "",
    chatRmAccessToken: "",
    rememberMe: false,
    menu: null,
    menuRights: null,
    projRight: null,
    sysParam: null,
  },
  mutations: {
    setIsLoggedIn: (state: any, resp: boolean) => {
      state.isLoggedIn = resp;
    },
    setUserData: (state: any, resp: any) => {
      state.userName = resp.UserName;
      state.userID = resp.UserID;
      state.EntNum = resp.EntNum;
      state.accessToken = resp.AccessToken;
      state.chatRmAccessToken = resp.ChatRmAccessToken;
      store.commit(storeCommitPath.setLang, resp.Language);
      store.commit(storeCommitPath.setCompCode, resp.CompCode);
    },
    setRememberMe: (state: any, resp: any) => {
      state.rememberMe = resp;
    },
    setMenu: (state: any, resp: any) => {
      state.menu = resp.Menu;
      state.menuRights = resp.Sec;
    },
    setProjRights: (state: any, resp: any) => {
      state.projRight = resp.data;
    },
    removeUserData: (state: any) => {
      state.userName = "";
      state.userID = "";
      state.accessToken = "";
      state.chatRmAccessToken = "";
      store.commit(storeCommitPath.setCompCode, "");
    },
    setSysParam: (state: any, resp: any) => {
      state.sysParam = resp;
    },
    setCompCode: (state: any, resp: any) => {
      state.compCode = resp;
    },
  },
  getters: {
    accessToken: (state: any) => {
      return state.accessToken ? state.accessToken : "";
    },
    userID: (state: any) => {
      return state.userID ? state.userID : "";
    },
    menuRights: (state: any) => {
      return state.menuRights ? state.menuRights : "";
    },
    EntNum: (state: any) => {
      return state.EntNum ? state.EntNum : "";
    },
  },
};
